package org.brownflat.lighthouse.web;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.ForwardResolution;

/**
 * <p>&copy Rupert Jones 2011</p>
 *
 * @author rup
 */
public abstract class AbstractAction implements ActionBean {

    private ActionBeanContext context;

    @Override
    public void setContext(ActionBeanContext actionBeanContext) {
        this.context = actionBeanContext;
    }

    protected ForwardResolution getForwardJSPResolution(String file) {
        return new ForwardResolution(String.format("/WEB-INF/jsp/%s", file));
    }

    protected ForwardResolution getForwardResolution(String url) {
        return new ForwardResolution(url);
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }

    public boolean isEmpty(String value) {
        if (value != null && value.length() > 0) {
            return false;
        }
        return true;
    }

    public String getParameterValue(String key) {
        return getContext().getRequest().getParameter(key);
    }
}
